//
//  MXFindDetailVC.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/13.
//  Copyright (c) 2015年 霄 马. All rights reserved.
// 专题的展示页

#import "MXFindDetailVC.h"
#import "AFNetworkHandler.h"
// 引入blockModel
#import "MXFindDetailModel.h"
// 引入productModel
#import "MXFindProductodel.h"

#import "UIImageView+WebCache.h"

#import "MJRefresh.h"

#import "MXImageSize.h"

#import "Height.h"
#import "SJAvatarBrowser.h"
#import "MXFindSearchVC.h"
#import "DataBaseFMDB.h"
#import <ShareSDK/ShareSDK.h>
#import "MXFindDBModel.h"
#import "MBProgressHUD.h"
//---------------------- 各种Block_Type的头文件(区分好) ---------------
/**
 * Block_Type:3 图片内用 有article属性 需要拆分字符串 前半是图片地址 后半是商品链接
 */
#import "MXFindBlockTypeThreeTableViewCell.h"
/**
 * Block_Type:4 文字内容 包含标题内容 加黑 加粗 加下划线
 */
#import "MXFindBlockTypeFourTableViewCell.h"
/**
 * Block_Type:2 商品展示 带商品详情(使用少)
 */
#import "MXFindTwoTableViewCell.h"
/**
 * Block_Type:6 商品展示 block字典中有图片 product中有图片中商品的滚动视图
 */
#import "MXFindBlockTypeSixTableViewCell.h"
/**
 * Block_Type:7 商品展示 点击图片显示商品详情页(砍了  只显示图片)
 */
#import "MXFindSevenTableViewCell.h"
/**
 * Block_Type:9 商品展示 3x2 6件商品展示
 */
#import "MXFindBlockTyprNineTableViewCell.h"
/**
 * Block_Type:10 商品展示 纯滚动的商品链接
 */
#import "MXFindTenTableViewCell.h"
/**
 * Block_Type:11 商品展示 显示5件商品 第一件事400x400 其余4件事200x200 带点击效果
 */
#import "MXFindBlockTypeElevenTableViewCell.h"
/**
 * Block_Type:13 商品展示 2x2 四件商品
 */
#import "MXFindThirdteenTableViewCell.h"

@interface MXFindDetailVC ()<UITableViewDataSource, UITableViewDelegate>
// 建立属性TableView
@property (nonatomic, retain) UITableView *tableView;
// 建立储存block数据的全局数组
@property (nonatomic, retain) NSMutableArray *blockArray;
// 建立储存product数据的全局数组
@property (nonatomic, retain) NSMutableArray *productArray;

@property (nonatomic, retain) UIButton *shoucangButton;

@property (nonatomic, retain) NSString *urlString;

@property (nonatomic, retain) NSString *imagePath;

@property (nonatomic, retain) MBProgressHUD *HUD;

@property (nonatomic, retain) UIView *alterView;
// 按钮属性
// 用model属性来判断自定义cell的类型

@end

@implementation MXFindDetailVC
- (void)dealloc
{
    [_HUD release];
    [_alterView release];
    [_imagePath release];
    [_urlString release];
    [_shoucangButton release];
    [_TempTitleString release];
    [_TempImage release];
    [_blockArray release];
    [_productArray release];
    [_TypeID release];
    [_AlbumID release];
    [_tableView release];
    [super dealloc];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // 全局数组初始化
    self.blockArray = [NSMutableArray array];
    
    self.productArray = [NSMutableArray array];
    
    self.navigationController.navigationBarHidden = YES;
    
    self.tabBarController.tabBar.hidden = YES;
    
    UIImageView *backgroundImageView = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
    [backgroundImageView sd_setImageWithURL:[NSURL URLWithString:self.TempImage]];
    [self.view addSubview:backgroundImageView];
    
    UIView *white = [[[UIView alloc] initWithFrame:backgroundImageView.bounds] autorelease];
    white.backgroundColor = [UIColor grayColor];
    white.alpha = 0.75;
    [backgroundImageView addSubview:white];
    
    
    // 引入数据
    [self GetData];
    


    
    // Do any additional setup after loading the view.
}

-(void)uiActivityindicatorviewStart
{
    self.alterView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)] autorelease];
    self.alterView.backgroundColor =[UIColor whiteColor];
    self.HUD = [MBProgressHUD showHUDAddedTo:self.alterView animated:YES];
//    self.HUD.labelText = @"正在努力的给您加载";
    [self.HUD show:YES];
    
    [self.view addSubview:self.alterView];
    
}
-(void)uiActivityindicatorviewEnd
{
    [self.alterView removeFromSuperview];
}

- (void)creatTableView
{
    
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, WIDTHPRO * 100, WIDTH,HEIGHTPRO * 200)] autorelease];
    
    
    UILabel *titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, headerView.frame.size.height - HEIGHTPRO * 50, WIDTH,HEIGHTPRO * 50)] autorelease];
    
    [titleLabel setTextColor:[UIColor blackColor]];
    
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    
    titleLabel.numberOfLines = 0;
    
    titleLabel.text = self.TempTitleString;
    
    headerView.backgroundColor = [UIColor clearColor];

    
    [headerView addSubview:titleLabel];
    
    self.tableView.tableHeaderView = headerView;
    
    self.tableView.tableHeaderView.backgroundColor = [UIColor clearColor];
    
    self.tableView.backgroundColor = [UIColor clearColor];
    
    [self.view addSubview:self.tableView];
    
//    [self.view insertSubview:backgroundImageView aboveSubview:self.tableView];
    
    [self uiActivityindicatorviewStart];
    
}
- (void)creatButtons
{
    //后退按钮
    UIButton *backButton  = [UIButton buttonWithType:(UIButtonTypeCustom)];
    backButton.frame = CGRectMake(WIDTHPRO * 20, HEIGHTPRO * 30, WIDTHPRO * 40, HEIGHTPRO * 40);
    backButton.layer.cornerRadius = 20;
    backButton.backgroundColor = [UIColor blackColor];
    backButton.alpha = 0.75;
    [backButton setBackgroundImage:[UIImage imageNamed:@"backButton"] forState:(UIControlStateNormal)];
    backButton.layer.masksToBounds = YES;
    [self.view addSubview:backButton];
    [backButton addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    //收藏按钮
    UIButton *shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    shareButton.frame = CGRectMake( WIDTH - WIDTHPRO * 60, HEIGHTPRO * 30, WIDTHPRO * 40,HEIGHTPRO * 40);
    shareButton.layer.cornerRadius = 20;
    shareButton.backgroundColor = [UIColor blackColor];
    shareButton.alpha = 0.75;
    [shareButton setBackgroundImage:[UIImage imageNamed:@"shareButton"] forState:(UIControlStateNormal)];
    shareButton.layer.masksToBounds = YES;
    [self.view addSubview:shareButton];
    [shareButton addTarget:self action:@selector(collectAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    self.shoucangButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.shoucangButton.frame = CGRectMake(WIDTH - WIDTHPRO * 60, HEIGHT - HEIGHTPRO * 70,WIDTHPRO * 40, HEIGHTPRO * 40);
    self.shoucangButton.layer.cornerRadius = WIDTHPRO * 20;
    self.shoucangButton.layer.masksToBounds = YES;
    self.shoucangButton.backgroundColor = [UIColor blackColor];
    [self.shoucangButton setBackgroundImage:[UIImage imageNamed:@"topic_uncollect"] forState:(UIControlStateNormal)];
    [self.shoucangButton setBackgroundImage:[UIImage imageNamed:@"collected"] forState:(UIControlStateSelected)];
    [self.view addSubview:self.shoucangButton];
    [self.shoucangButton addTarget:self action:@selector(shoucangAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    DataBaseFMDB *dbManger = [[[DataBaseFMDB alloc] init] autorelease];
    
    // 创建数据库
    [dbManger createTopicDataBase];
    
    // 创建表
    [dbManger creatTopicDaseTable];

    
    BOOL exists = [dbManger isTopicExists:self.TempTitleString];
    if (exists) {
        self.shoucangButton.selected = YES;
    }

    
    
    
    UIButton *searchButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [searchButton setBackgroundImage:[UIImage imageNamed:@"search_white"] forState:(UIControlStateNormal)];
    searchButton.frame = CGRectMake(WIDTHPRO * 20, HEIGHT - HEIGHTPRO * 70, WIDTHPRO * 40,HEIGHTPRO * 40);
    searchButton.layer.cornerRadius = WIDTHPRO * 20;
    searchButton.layer.masksToBounds = YES;
    searchButton.backgroundColor = [UIColor blackColor];
    searchButton.alpha = 0.75;
    [self.view addSubview:searchButton];
    [searchButton addTarget:self action:@selector(sousuoAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    
}
#pragma mark - 数据解析
#warning 比较繁琐 加好注释!!!
/******************************* 数据解析部分 *******************************/
- (void)GetData
{
       NSString *Path = [NSString stringWithFormat:@"http://rm.app.hongniujia.com/json_rm.php?action=detail&albumId=%@&album_type=%@&appCookie=channel_AppStore20version_6.11%%20oid_AE53CF37-EAEB-468C-8507-15A922FDD348%%20package_com.aslibra.rm.nanren%%20platform_iphone%%20ver_8.4%%20jb_0%%20t1_1438685676%%20md5_10%%20t_1438671553", self.AlbumID, self.TypeID];
    [AFNetworkHandler GETwithAFNByURL:Path completion:^(id result) {
//============================== block(字典) =============================
//         建立字典接受数据
        NSArray *dataArr = [result objectForKey:@"data"];
        for (NSDictionary *blockDict in dataArr) {
            NSDictionary *block_Dict = [blockDict objectForKey:@"block"];
               MXFindDetailModel *blockModel = [[[MXFindDetailModel alloc] initWithDic:block_Dict] autorelease];
                blockModel.product = [blockDict objectForKey:@"product"];

                [self.blockArray addObject:blockModel];
            
            self.urlString = blockModel.article;
            self.imagePath = blockModel.article;
//============================== product(数组) =============================
#warning 直接利用KVC赋值 就不需要判断数据类型
#warning self.productArray 数组需要到自定义cell中解析 单独创建一个方法 懒加载

        }
    // 没有数据的更新 不需要relodata
        [self creatTableView];
        [self creatButtons];
        [self uiActivityindicatorviewEnd];
    }];
    
}
/******************************* TableView Delegate 协议实现 *******************************/
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// 根据数组定数目
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// 根据数组定数目
    return self.blockArray.count;
}

// 重用机制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    /**
     * 判断type的类型 自定义cell 进入到重用池
     */
//    NSLog(@"%@",[self.blockArray[indexPath.row] block_type]);
    
    MXFindDetailModel *model = self.blockArray[indexPath.row];
    
//    NSLog(@"type ----- %@", model.block_type);
//    NSLog(@"block ----- %@", model.block);
//    NSLog(@"article ----- %@", model.article);
//    NSLog(@"albumType--------%@", model.album_type);
//    NSLog(@"productArr ----- %@", model.product);
    
    
    NSString * str = [NSString stringWithFormat:@"%@",[self.blockArray[indexPath.row] block_type] ];
#pragma mark - Type ------ 3
    if ([str  isEqualToString:@"3"]) {
        
        MXFindBlockTypeThreeTableViewCell *threeCell = [tableView dequeueReusableCellWithIdentifier:@"three"];
        
        if (!threeCell) {
            threeCell = [[MXFindBlockTypeThreeTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"three"];
            
        }
         NSString *albumType = [NSString stringWithFormat:@"%@", [self.blockArray[indexPath.row] album_type]];
        
        threeCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if ([albumType isEqualToString:@"0"]) {
            
            threeCell.height = HEIGHTPRO * 500;
            
        } else if ([albumType isEqualToString:@"4"]){
            NSString *string = [self.blockArray[indexPath.row] article];
            
            
            if ([string hasPrefix:@"http://gw"]) {
                
                threeCell.height = HEIGHTPRO * 300;
                
            }  else {
                NSArray *FirstArr = [string componentsSeparatedByString:@"|"];
                
                NSString *FirstString = [FirstArr objectAtIndex:0];
                
                
                NSArray *secondArr = [FirstString componentsSeparatedByString:@"="];
                
                NSString *secondpString = [secondArr objectAtIndex:1];
                
                NSArray *heightArr = [secondpString componentsSeparatedByString:@"."];
                
                NSString *heightStr = [heightArr objectAtIndex:1];
                
                CGFloat tempHeight = heightStr.floatValue;
                
                
                threeCell.height = HEIGHTPRO * tempHeight;
                
            }
            
        }
        
        // 向自定义传递数据
        [threeCell getBlockModel:self.blockArray[indexPath.row] productArr:self.productArray];
        
        return threeCell;
        
#pragma mark - Type ------ 4
        
    } else  if([str isEqualToString:@"4"]) {
        
        MXFindBlockTypeFourTableViewCell *fourCell = [tableView dequeueReusableCellWithIdentifier:@"four"];
        
        if (!fourCell) {
            
            fourCell = [[MXFindBlockTypeFourTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"four"];
            
        }
        
        fourCell.selectionStyle = UITableViewCellSelectionStyleNone;

        
        [fourCell getBlockModel:self.blockArray[indexPath.row] productArr:self.productArray];
        
        
        return fourCell;
        
#pragma mark - Type ------ 2
        
    }if ([str  isEqualToString:@"2"]) {
        
        MXFindTwoTableViewCell *twoCell = [tableView dequeueReusableCellWithIdentifier:@"two"];
        
        if (!twoCell) {
            
            twoCell = [[MXFindTwoTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"two"];
            
        }
        
        twoCell.naviTwo = self.navigationController;
        
        twoCell.selectionStyle = UITableViewCellSelectionStyleNone;

        
        twoCell.model = self.blockArray[indexPath.row];
        
        return twoCell;
        
#pragma mark - Type ------ 6
        
    }if ([str  isEqualToString:@"6"]) {
        
        MXFindBlockTypeSixTableViewCell *sixCell = [tableView dequeueReusableCellWithIdentifier:@"six"];
        
        if (!sixCell) {
            
            sixCell = [[MXFindBlockTypeSixTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"six"];
            
        }
        
        sixCell.selectionStyle = UITableViewCellSelectionStyleNone;

        
//            [sixCell getBlockModel:self.blockArray[indexPath.row] productArr:self.productArray];

        sixCell.model = self.blockArray[indexPath.row];
        
// 设置导航控制器
        sixCell.naviSix = self.navigationController;
        
        
        return sixCell;
        
#pragma mark - Type ------ 7
        
    } if ([str  isEqualToString:@"7"]) {
        
        MXFindSevenTableViewCell *svenCell = [tableView dequeueReusableCellWithIdentifier:@"seven"];
        
        if (!svenCell) {
            
            svenCell = [[MXFindSevenTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"seven"];
            
        }
        
        svenCell.model = self.blockArray[indexPath.row];
        
        svenCell.selectionStyle = UITableViewCellSelectionStyleNone;

        
        return svenCell;
#pragma mark - Type ------ 9
        
    } if ([str  isEqualToString:@"9"]) {
        
        MXFindBlockTyprNineTableViewCell *nineCell = [tableView dequeueReusableCellWithIdentifier:@"nine"];
        
        if (!nineCell) {
            
            nineCell = [[MXFindBlockTyprNineTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"nine"];
            
        }
        
        nineCell.model = self.blockArray[indexPath.row];
        
        nineCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        nineCell.naviNine = self.navigationController;
        
        [nineCell.collectionView reloadData];
        
        
        return nineCell;
        
#pragma mark - Type ------ 10
        
    }if ([str  isEqualToString:@"10"]) {
        
        MXFindTenTableViewCell *tenCell = [tableView dequeueReusableCellWithIdentifier:@"ten"];
        
        if (!tenCell) {
            
            tenCell = [[MXFindTenTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"yen"];
            
        }
        
        tenCell.selectionStyle = UITableViewCellSelectionStyleNone;

        
        return tenCell;
        
#pragma mark - Type ------ 11
        
    } if ([str  isEqualToString:@"11"]) {
        
        MXFindBlockTypeElevenTableViewCell *elevenCell = [tableView dequeueReusableCellWithIdentifier:@"eleven"];
        
        if (!elevenCell) {
            
            elevenCell = [[MXFindBlockTypeElevenTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"eleven"];
            
        }
        
        elevenCell.model = self.blockArray[indexPath.row];
        
        elevenCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        elevenCell.naviEleven = self.navigationController;
        
        [elevenCell.collectionView reloadData];
        
        return elevenCell;
        
#pragma mark - Type ------ 13
        
    } if ([str  isEqualToString:@"13"]) {
        
        MXFindThirdteenTableViewCell *thirteenCell = [tableView dequeueReusableCellWithIdentifier:@"thirteen"];
        
        if (!thirteenCell) {
            
            thirteenCell = [[MXFindThirdteenTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"thirteen"];
            
        }
        thirteenCell.naviThirteen = self.navigationController;
        
        thirteenCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        thirteenCell.model = self.blockArray[indexPath.row];
                
        return thirteenCell;
    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"reuse"];
    }
    cell.textLabel.text = @"test";
    
    return cell;
}

    
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
#pragma mark 自适应行高 ========== 3
#warning 自适应行高
    NSString * str = [NSString stringWithFormat:@"%@",[self.blockArray[indexPath.row] block_type] ];
    NSString *albumType = [NSString stringWithFormat:@"%@", [self.blockArray[indexPath.row] album_type]];

    if ([str  isEqualToString:@"3"]) {
        
        if ([albumType isEqualToString:@"0"]) {
            
            return HEIGHTPRO * 500;
            
        } else if([albumType isEqualToString:@"4"]){
            
            NSString *string = [self.blockArray[indexPath.row] article];
            
            if ([string hasPrefix:@"http://gw"]) {
                
                return HEIGHTPRO * 300;
                
            } else {
                
                NSArray *FirstArr = [string componentsSeparatedByString:@"|"];
                
                NSString *FirstString = [FirstArr objectAtIndex:0];
                
                
                NSArray *secondArr = [FirstString componentsSeparatedByString:@"="];
                
                NSString *secondpString = [secondArr objectAtIndex:1];
                
                NSArray *heightArr = [secondpString componentsSeparatedByString:@"."];
                
                NSString *heightStr = [heightArr objectAtIndex:1];
                
                NSString *widthStr = [heightArr objectAtIndex:0];
                
                CGFloat tempHeight = heightStr.floatValue;
                
                
                return HEIGHTPRO * tempHeight;
            }
            
            return HEIGHTPRO * 300;
            
        }

#pragma mark 自适应行高 ========== 4
    } else if([str isEqualToString:@"4"]) {
    
        CGFloat textHeight = [Height getTextHeight:[self.blockArray[indexPath.row] article] Wid:WIDTH Font:18];
        
        return  textHeight;
        
#pragma mark 自适应行高 ========== 6

    } else if ([str isEqualToString:@"6"]) {
        
        return HEIGHTPRO * 450;
        
#pragma mark 自适应行高 ========== 11

    } else if ([str isEqualToString:@"11"]) {
        return HEIGHTPRO * 660;
        
#pragma mark 自适应行高 ========== 7

    } else if ([str isEqualToString:@"7"]) {
        
        return HEIGHTPRO * 420;
        
#pragma mark 自适应行高 ========== 9
        
    } else if ([str isEqualToString:@"9"]) {
        
        return HEIGHTPRO * 500;
        
#pragma mark 自适应行高 ========== 2

    } else if ([str isEqualToString:@"2"]){
        
        MXFindDetailModel *model = self.blockArray[indexPath.row];
        
        return HEIGHTPRO * 100 * model.product.count;
        
#pragma mark 自适应行高 ========== 10
        
    } else if ([str isEqualToString:@"10"]){
        
        return 0;
        
#pragma mark 自适应行高 ========== 13

    } else if ([str isEqualToString:@"13"]) {
        
        return HEIGHTPRO * 320;
        
    }
    return HEIGHTPRO * 200;
}

#pragma mark - TableView 点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSString * str = [NSString stringWithFormat:@"%@",[self.blockArray[indexPath.row] block_type] ];
#pragma mark -__________________ 3 点击方法 (图片浏览器)
    if ([str isEqualToString:@"3"]) {
        if (!([[self.blockArray[indexPath.row] article] isEqualToString:@""])) {
            
            NSString *string = [[self.blockArray[indexPath.row] article] stringByReplacingOccurrencesOfString:@"|" withString:@""];
            
            UIImageView *img = [[UIImageView alloc] init];
            [img sd_setImageWithURL:[NSURL URLWithString:string] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                [SJAvatarBrowser showImage:img];
            }];
        }
    }
#pragma mark -__________________ 6 点击方法
    if ([str isEqualToString:@"6"]) {
    }
}

#pragma mark - 按钮的点击方法
- (void)backAction
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)collectAction
{
    
    //创建弹出菜单容器
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    
    NSArray* imageArray = @[[UIImage imageNamed:@"shareImage"]];
    
    if (imageArray) {
        
        [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                         images:imageArray
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"分享标题"
                                           type:SSDKContentTypeImage];
        
        //进行分享
        [ShareSDK share:SSDKPlatformTypeSinaWeibo
             parameters:shareParams
         onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
             
             //             [theController showLoadingView:NO];
             //             [theController.tableView reloadData];
             
             switch (state) {
                 case SSDKResponseStateSuccess:
                 {
                     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                         message:nil
                                                                        delegate:nil
                                                               cancelButtonTitle:@"确定"
                                                               otherButtonTitles:nil];
                     [alertView show];
                     break;
                 }
                 case SSDKResponseStateFail:
                 {
                     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                         message:[NSString stringWithFormat:@"%@", error]
                                                                        delegate:nil
                                                               cancelButtonTitle:@"确定"
                                                               otherButtonTitles:nil];
                     [alertView show];
                     break;
                 }
                 case SSDKResponseStateCancel:
                 {
                     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"
                                                                         message:nil
                                                                        delegate:nil
                                                               cancelButtonTitle:@"确定"
                                                               otherButtonTitles:nil];
                     [alertView show];
                     break;
                 }
                 default:
                     break;
             }
             
         }];
    }
    
}

#pragma mark - 收藏
- (void)shoucangAction:(UIButton *)shoucangButton
{
    DataBaseFMDB *dbManger = [[[DataBaseFMDB alloc] init] autorelease];
    
    // 创建数据库
    [dbManger createTopicDataBase];
    
    // 创建表
    [dbManger creatTopicDaseTable];
    
    BOOL exists = [dbManger isTopicExists:self.TempTitleString];
    
    shoucangButton.selected = !shoucangButton.selected;
    
    if (shoucangButton.selected == YES) {
        [dbManger insertTopicTable:self.TempTitleString AlbumID:self.AlbumID TypeID:self.TypeID imagePath:self.TempImage];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏成功!" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil , nil];
        [alert show];
        [alert release];
        
    } else if (exists){
        //        collectButton.selected = YES;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"取消收藏" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil , nil];
        [alert show];
        [alert release];
        
        [dbManger deleteTopicData:self.TempTitleString];
        
    }

}

- (void)sousuoAction
{    
    MXFindSearchVC *searchVC = [[[MXFindSearchVC alloc] init] autorelease];

    [self.navigationController pushViewController:searchVC animated:YES];
    
    
}

#pragma mark - 开始拖拽
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    self.tabBarController.tabBar.hidden = YES;
}

#pragma mark - 结束减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//    self.tabBarController.tabBar.hidden = NO;
}

-(void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}



@end
